package net.discard.model;

import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_erupt.Power;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.EditType;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.annotation.sub_field.ViewType;
import xyz.erupt.annotation.sub_field.sub_edit.AttachmentType;
import xyz.erupt.annotation.sub_field.sub_edit.HtmlEditorType;
import xyz.erupt.annotation.sub_field.sub_edit.InputType;
import xyz.erupt.annotation.sub_field.sub_edit.Search;
import xyz.erupt.upms.model.base.HyperModel;

import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.util.Date;

/**
 * @Author: Discard
 * @Date: 2021/2/8 2:18 下午
 */
@Erupt(name = "商品管理",
        power = @Power(importable = true, export = true),
        orderBy = "id desc"
)
@Entity
@Table(name = "goods")
public class Goods extends HyperModel {

    @EruptField(
            views = @View(title = "名称"),
            edit = @Edit(
                    title = "商品名称", notNull = true, inputType = @InputType, search = @Search(vague = true)
            )
    )
    private String name;


    @EruptField(
            views = @View(title = "价格", sortable = true, type = ViewType.NUMBER),
            edit = @Edit(
                    title = "价格", notNull = true, type = EditType.NUMBER
            )
    )
    private BigDecimal price;

    @EruptField(
            views = @View(title = "图片"),
            edit = @Edit(
                    title = "图片", notNull = true, type = EditType.ATTACHMENT,
                    attachmentType = @AttachmentType(type = AttachmentType.Type.IMAGE))
    )
    private String image;

    @Lob
    @EruptField(
            edit = @Edit(title = "商品详情",
                    type = EditType.HTML_EDITOR,
                    htmlEditorType = @HtmlEditorType(HtmlEditorType.Type.CKEDITOR))
    )
    private String details;

    @CreatedDate
    public Date createTime;

    @LastModifiedDate
    public Date updateTime;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public String getDetails() {
        return details;
    }

    public void setDetails(String details) {
        this.details = details;
    }

    @Override
    public Date getCreateTime() {
        return createTime;
    }

    @Override
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    @Override
    public Date getUpdateTime() {
        return updateTime;
    }

    @Override
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}
